import axios from 'axios'
import {Message} from 'element-ui'

const service = axios.create({
    baseURL: process.env.BASE_API,
    timeout: 3 * 1000
})

// 配置请求拦截器
service.interceptors.request.use(config => {
    config.data = JSON.stringify(config.data)
    config.headers = {
        'Content-Type':'application/x-www-form-urlencoded'
    }
    return config
}, error => {
    Promise.reject(error)
})

// 配置响应拦截器
service.interceptors.response.use(response => {
    return response
}, error => {
    // 公共响应异常处理 error.response.status 状态码
    return Promise.resolve(error.response)
})

export default service